From 1110e79b188b7d1fb797efb0c3453a38c96e66c0 Mon Sep 17 00:00:00 2001 From: Debian Science Maintainers Date: Sat, 2 Mar 2019 14:59:35 +0000 Subject: [PATCH] Use cached datasets for building documentation/examples Also remove a download that isn't actually used in that example. This allows at least some of the examples to be built in an offline environment such as a Debian buildd. See debian/README.source for more information about the cached datasets. Author: Diane Trout , Rebecca N. Palmer Gbp-Pq: Name use-cached-datasets --- docs/source/contingency_tables.rst | 4 ++-- docs/source/datasets/index.rst | 2 +- docs/source/duration.rst | 4 ++-- docs/source/example_formulas.rst | 2 +- docs/source/gee.rst | 2 +- docs/source/gettingstarted.rst | 2 +- docs/source/index.rst | 2 +- docs/source/mixed_linear.rst | 2 +- docs/source/release/version0.6.rst | 2 +- examples/notebooks/markov_regression.ipynb | 6 +----- examples/notebooks/mixed_lm_example.ipynb | 4 ++-- examples/notebooks/regression_diagnostics.ipynb | 3 +-- 12 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/source/contingency_tables.rst b/docs/source/contingency_tables.rst index 4bc5393..e66c215 100644 --- a/docs/source/contingency_tables.rst +++ b/docs/source/contingency_tables.rst @@ -49,7 +49,7 @@ contingency table cell counts: import pandas as pd import statsmodels.api as sm - df = sm.datasets.get_rdataset("Arthritis", "vcd").data + df = sm.datasets.get_rdataset("Arthritis", "vcd", cache=True).data tab = pd.crosstab(df['Treatment'], df['Improved']) tab = tab.loc[:, ["None", "Some", "Marked"]] @@ -182,7 +182,7 @@ contingency table. .. ipython:: python - df = sm.datasets.get_rdataset("VisualAcuity", "vcd").data + df = sm.datasets.get_rdataset("VisualAcuity", "vcd", cache=True).data df = df.loc[df.gender == "female", :] tab = df.set_index(['left', 'right']) del tab["gender"] diff --git a/docs/source/datasets/index.rst b/docs/source/datasets/index.rst index 3220dbe..171014d 100644 --- a/docs/source/datasets/index.rst +++ b/docs/source/datasets/index.rst @@ -30,7 +30,7 @@ The `Rdatasets project `__ gives .. ipython:: python import statsmodels.api as sm - duncan_prestige = sm.datasets.get_rdataset("Duncan", "car") + duncan_prestige = sm.datasets.get_rdataset("Duncan", "car", cache=True) print(duncan_prestige.__doc__) duncan_prestige.data.head(5) diff --git a/docs/source/duration.rst b/docs/source/duration.rst index fc71ecf..7dd93a4 100644 --- a/docs/source/duration.rst +++ b/docs/source/duration.rst @@ -42,7 +42,7 @@ We fit the survival distribution only for the female subjects. import statsmodels.api as sm - data = sm.datasets.get_rdataset("flchain", "survival").data + data = sm.datasets.get_rdataset("flchain", "survival", cache=True).data df = data.loc[data.sex == "F", :] sf = sm.SurvfuncRight(df["futime"], df["death"]) @@ -155,7 +155,7 @@ Examples import statsmodels.api as sm import statsmodels.formula.api as smf - data = sm.datasets.get_rdataset("flchain", "survival").data + data = sm.datasets.get_rdataset("flchain", "survival", cache=True).data del data["chapter"] data = data.dropna() data["lam"] = data["lambda"] diff --git a/docs/source/example_formulas.rst b/docs/source/example_formulas.rst index c1f6d68..411e757 100644 --- a/docs/source/example_formulas.rst +++ b/docs/source/example_formulas.rst @@ -45,7 +45,7 @@ and list-wise delete to remove missing observations: .. ipython:: python - df = sm.datasets.get_rdataset("Guerry", "HistData").data + df = sm.datasets.get_rdataset("Guerry", "HistData", cache=True).data df = df[['Lottery', 'Literacy', 'Wealth', 'Region']].dropna() df.head() diff --git a/docs/source/gee.rst b/docs/source/gee.rst index edaaf9d..e1ba353 100644 --- a/docs/source/gee.rst +++ b/docs/source/gee.rst @@ -24,7 +24,7 @@ within clusters using data on epilepsy seizures. import statsmodels.api as sm import statsmodels.formula.api as smf - data = sm.datasets.get_rdataset('epil', package='MASS').data + data = sm.datasets.get_rdataset('epil', package='MASS', cache=True).data fam = sm.families.Poisson() ind = sm.cov_struct.Exchangeable() diff --git a/docs/source/gettingstarted.rst b/docs/source/gettingstarted.rst index 054eae9..530093b 100644 --- a/docs/source/gettingstarted.rst +++ b/docs/source/gettingstarted.rst @@ -43,7 +43,7 @@ We could download the file locally and then load it using ``read_csv``, but .. ipython:: python - df = sm.datasets.get_rdataset("Guerry", "HistData").data + df = sm.datasets.get_rdataset("Guerry", "HistData", cache=True).data The `Input/Output doc page `_ shows how to import from various other formats. diff --git a/docs/source/index.rst b/docs/source/index.rst index 6f544a2..48f7aa1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -25,7 +25,7 @@ example using ordinary least squares: import statsmodels.formula.api as smf # Load data - dat = sm.datasets.get_rdataset("Guerry", "HistData").data + dat = sm.datasets.get_rdataset("Guerry", "HistData", cache=True).data # Fit regression model (using the natural log of one of the regressors) results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit() diff --git a/docs/source/mixed_linear.rst b/docs/source/mixed_linear.rst index 7cbfe85..a57bc56 100644 --- a/docs/source/mixed_linear.rst +++ b/docs/source/mixed_linear.rst @@ -35,7 +35,7 @@ Examples import statsmodels.api as sm import statsmodels.formula.api as smf - data = sm.datasets.get_rdataset("dietox", "geepack").data + data = sm.datasets.get_rdataset("dietox", "geepack", cache=True).data md = smf.mixedlm("Weight ~ Time", data, groups=data["Pig"]) mdf = md.fit() diff --git a/docs/source/release/version0.6.rst b/docs/source/release/version0.6.rst index 1f3c7ad..d9c0c6a 100644 --- a/docs/source/release/version0.6.rst +++ b/docs/source/release/version0.6.rst @@ -43,7 +43,7 @@ covariates. import statsmodels.api as sm import statsmodels.formula.api as smf - data = sm.datasets.get_rdataset("epil", "MASS").data + data = sm.datasets.get_rdataset("epil", "MASS", cache=True).data md = smf.gee("y ~ age + trt + base", "subject", data, cov_struct=sm.cov_struct.Independence(), diff --git a/examples/notebooks/markov_regression.ipynb b/examples/notebooks/markov_regression.ipynb index 48e174c..b4b1a11 100644 --- a/examples/notebooks/markov_regression.ipynb +++ b/examples/notebooks/markov_regression.ipynb @@ -28,11 +28,7 @@ "import pandas as pd\n", "import statsmodels.api as sm\n", "import matplotlib.pyplot as plt\n", - "\n", - "# NBER recessions\n", - "from pandas_datareader.data import DataReader\n", - "from datetime import datetime\n", - "usrec = DataReader('USREC', 'fred', start=datetime(1947, 1, 1), end=datetime(2013, 4, 1))" + "from datetime import datetime\n" ] }, { diff --git a/examples/notebooks/mixed_lm_example.ipynb b/examples/notebooks/mixed_lm_example.ipynb index b6e21a7..672aac8 100644 --- a/examples/notebooks/mixed_lm_example.ipynb +++ b/examples/notebooks/mixed_lm_example.ipynb @@ -75,7 +75,7 @@ }, "outputs": [], "source": [ - "data = sm.datasets.get_rdataset('dietox', 'geepack').data\n", + "data = sm.datasets.get_rdataset('dietox', 'geepack', cache=True).data\n", "md = smf.mixedlm(\"Weight ~ Time\", data, groups=data[\"Pig\"])\n", "mdf = md.fit()\n", "print(mdf.summary())" @@ -225,7 +225,7 @@ }, "outputs": [], "source": [ - "data = sm.datasets.get_rdataset(\"Sitka\", \"MASS\").data\n", + "data = sm.datasets.get_rdataset(\"Sitka\", \"MASS\", cache=True).data\n", "endog = data[\"size\"]\n", "data[\"Intercept\"] = 1\n", "exog = data[[\"Intercept\", \"Time\"]]" diff --git a/examples/notebooks/regression_diagnostics.ipynb b/examples/notebooks/regression_diagnostics.ipynb index 7bed710..377d78c 100644 --- a/examples/notebooks/regression_diagnostics.ipynb +++ b/examples/notebooks/regression_diagnostics.ipynb @@ -43,8 +43,7 @@ "import matplotlib.pyplot as plt\n", "\n", "# Load data\n", - "url = 'http://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'\n", - "dat = pd.read_csv(url)\n", + "dat = statsmodels.datasets.get_rdataset(\"Guerry\", \"HistData\", cache=True).data\n", "\n", "# Fit regression model (using the natural log of one of the regressaors)\n", "results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()\n", -- 2.30.2